package com.avic.map.common.convertor;
import com.avic.map.common.constant.AppConstant;
import com.avic.map.controller.info.MapUavResourceListInfo;
import com.avic.map.controller.info.UavResourceListInfo;
import com.avic.map.dal.model.MapUavResource;
import com.avic.map.dal.model.UavResource;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 车辆资源对象转换器
 */
public class UavResourceConvertor {


    public static List<UavResourceListInfo> uavResourceListVOToUavResourceListInfo(List<UavResource> uavResources) {
        List<UavResourceListInfo> uavResourceListInfos = new ArrayList<>();
        if (null != uavResources && uavResources.size() > 0) {
            uavResources.forEach(uavResource -> {
                UavResourceListInfo uavResourceListInfo = new UavResourceListInfo();
                uavResourceListInfo.setCreateTime(StringUtils.isNotBlank(uavResource.getCreateTime()) ?
                        StringUtils.substringBefore(uavResource.getCreateTime(), AppConstant.MYBATIS_DATA_TIME_SEPARATOR) : StringUtils.EMPTY);
                uavResourceListInfo.setId(uavResource.getId());
                uavResourceListInfo.setUavName(uavResource.getUavName());
                uavResourceListInfo.setUavNumber(uavResource.getUavNumber());
                uavResourceListInfo.setUavRtsp(uavResource.getUavRtsp());
                uavResourceListInfo.setId(uavResource.getId());
                uavResourceListInfos.add(uavResourceListInfo);
            });
        }
        return uavResourceListInfos;
    }

    public static List<MapUavResourceListInfo> mapUavResourceListsInfoToMapUavResources(List<MapUavResource> mapUavResources) {
        List<MapUavResourceListInfo> uavResourceListInfos = new ArrayList<>();
        if (null != mapUavResources && mapUavResources.size() > 0) {
            mapUavResources.forEach(uavResource -> {
                MapUavResourceListInfo mapUavResourceListInfo = new MapUavResourceListInfo();
                mapUavResourceListInfo.setUavName(uavResource.getUavName());
                mapUavResourceListInfo.setUavNumber(uavResource.getUavNumber());
                mapUavResourceListInfo.setUavRtsp(uavResource.getUavRtsp());
                mapUavResourceListInfo.setUavState(uavResource.getUavState());
                mapUavResourceListInfo.setLongitude(uavResource.getLongitude());
                mapUavResourceListInfo.setLatitude(uavResource.getLatitude());
                uavResourceListInfos.add(mapUavResourceListInfo);
            });
        }
        return uavResourceListInfos;
    }

}
